/*
 * @Date: 2022-11-07 13:17:36
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-11-08 10:47:45
 * @FilePath: \vue-admin-ts\src\views\Login\components\login-pannel\options.ts
 * @Description: 登陆面板表单配置项
 */
import type { FormOptions } from "@/components/Form/type/type";
const validatePhone = (rule: any, value: string, cb: any) => {
  const regPhone = (value: string) => {
    let reg =
      /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/;
    return !reg.test(value) ? true : false;
  };
  if (value === "") cb(new Error("手机号不正确"));
  else if (regPhone(value)) {
    cb(new Error("手机号格式有误！"));
  } else {
    cb();
  }
};
export const userNameOptions: FormOptions[] = [
  {
    type: "input",
    value: "",
    label: "账号",
    prop: "userName",
    placeholder: "请输入账号",
    rules: [
      {
        required: true,
        message: "账号不能为空",
        trigger: "blur",
      },
    ],
  },
  {
    type: "input",
    value: "",
    label: "密码",
    prop: "password",
    placeholder: "请输入密码",
    attrs: {
      clearable: true,
      showPassword: true,
    },
    rules: [
      {
        required: true,
        message: "密码不能为空",
        trigger: "blur",
      },
    ],
  },
];
export const phoneFormOptions: FormOptions[] = [
  {
    type: "input",
    value: "",
    label: "手机号",
    prop: "phone",
    placeholder: "请输入手机号",
    rules: [
      {
        required: true,
        message: "手机号不能为空",
        trigger: "blur",
      },
      {
        validator: validatePhone,
        trigger: "blur",
      },
    ],
  },
  {
    slot: "code",
    type: "input",
    value: "",
    label: "验证码",
    prop: "code",
    placeholder: "请输入验证码",
    rules: [
      {
        required: true,
        message: "验证码不能为空",
        trigger: "blur",
      },
    ],
  },
];
